package com.example.arithmeticleetcode.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @program: arithmetic-leetcode
 * @description: 1207. 独一无二的出现次数
 * @author: FangZhen
 * @create: 2020-04-28 13:27
 **/
public class Demo09 {

    public static void main(String[] args) {
        int[] arr = {1, 2, 2, 1, 1, 3};//true
        int[] arr1 = {1, 2};//false
        int[] arr2 = {-3, 0, 1, -3, 1, 1, 1, -3, 10, 0};//true
        System.out.println(uniqueOccurrences(arr));
        System.out.println(uniqueOccurrences(arr1));
        System.out.println(uniqueOccurrences(arr2));
    }

    public static boolean uniqueOccurrences(int[] arr) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : arr) {
            map.put(i, map.getOrDefault(i, 0) + 1);
        }
        Set<Integer> set = map.values().stream().collect(Collectors.toSet());
        return map.size() == set.size() ? true : false;
    }
}
